var date = new Date();
var year = date.getFullYear();
var month = date.getMonth()+1;
var day = date.getDate();
var weeks = ["日","一","二","三","四","五","六"];
//当前月天数
var days = mGetDate(year,month);
//当前月第一天是星期几
var week = mGetWeek(year,month);
//渲染表格
function renderTable(){
	var calendar = document.getElementById("calendar");
	var html = "<table id='my_table' cellpadding='0' cellspacing='0'><tr><td class='bg_gray' rowspan='2'>序号</td><td class='bg_gray' rowspan='2'>姓名</td><td class='bg_gray' rowspan='2'>角色</td>";
	var yearsRow = "<tr>";
	var weekFlag = week;
	for(var i = 0;i<days;i++){
		if (weekFlag == 0 || weekFlag == 6){
			html += "<td  class='bg_gray'>"+weeks[weekFlag]+"</td>";
			yearsRow += "<td  class='bg_gray'>" + (i+1) + "</td>";
		}else{
			html += "<td>"+weeks[weekFlag]+"</td>";
			yearsRow += "<td>" + (i+1) + "</td>";
		}
		
		if (weekFlag == 6){
			weekFlag = 0;
		}else{
			weekFlag ++;
		}
	}
	yearsRow += "</tr>";
	html += yearsRow + "</tr></table>";
	calendar.innerHTML = html;
}
//获取月天数
function mGetDate(year,month){
     return new Date(year, month, 0).getDate();
}
function mGetWeek(year,month){
	return new Date(year,month,1).getDay();
}
//修改这个方法即可
//在这个方法中加入你从数据库里查的数据
function test_add(){
	var last_row = document.getElementById("my_table").lastChild;
	var newnode=document.createElement("tr");
	var weekFlag = week;
	var html = "<td>1</td><td>张三</td><td>经理</td>"
	/**
	 * 这是你要写的行内容
	 * 
	 */
	for(var i = 1;i<= days;i++){
		if(weekFlag == 0 || weekFlag == 6 || i > day){
			html += "<td></td>";
		}else{
			//绿色class是circle_green ，红色是circle_red
			html += "<td><div class='circle_red'></div></td>";
		}
	}
	newnode.innerHTML = html;
	last_row.appendChild(newnode);
}

renderTable();
test_add();